package com.security.common.code;

import com.security.common.code.image.ImageValidateCodeGenerator;
import com.security.common.code.sms.DefaultSendProcessor;
import com.security.common.code.sms.SendProcessor;
import com.security.common.code.sms.SmsValidateCodeGenerator;
import com.security.common.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: TongRui乀
 * @Date: 2020/3/21 14:27
 * @description：  配置加载默认生效的验证码生成器
 */
@Configuration
public class ValidateCodeGeneratorConfig {

    @Autowired
    private SecurityProperties securityProperties;

    /**
     *  默认的验证码生成器  子类可覆盖
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ValidateCodeGenerator imageValidateCodeGenerator(){
        ImageValidateCodeGenerator generator = new ImageValidateCodeGenerator();
        generator.setSecurityProperties(securityProperties);
        return generator;
    }


    @Bean
    @ConditionalOnMissingBean(name = "smsValidateCodeGenerator")
    public ValidateCodeGenerator smsValidateCodeGenerator(){
        SmsValidateCodeGenerator generator = new SmsValidateCodeGenerator();
        generator.setSecurityProperties(securityProperties);
        return generator;
    }


    @Bean
    @ConditionalOnMissingBean(SendProcessor.class)
    public SendProcessor sendProcessor(){
        return new DefaultSendProcessor();
    }

}
